package com.dgut.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.dgut.common.SelectRole;
import com.dgut.pojo.Article;
import com.dgut.service.ArticleService;
import com.dgut.utils.PageRequestInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@CrossOrigin
@Api("ArticleController")
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Resource
    private ArticleService articleService;
    /**
     * start-zwb
     */
    @ApiOperation(value = "获取文章表")
    @PostMapping("/getArticleList")
    public Object getArticleList(@ApiParam(value = "分页信息",required = true) @RequestBody PageRequestInfo pageRequestInfo) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("articleList",articleService.getArticleList(pageRequestInfo));
        return map;
    }
    @ApiOperation(value = "获取已发布文章表")
    @PostMapping("/getPublishedArticleList")
    public Object getPublishedArticleList(@ApiParam(value = "分页信息",required = true) @RequestBody PageRequestInfo pageRequestInfo) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("articleList",articleService.getPublishedArticleList(pageRequestInfo));
        return map;
    }
    @ApiOperation(value = "通过文章标题获取文章表")
    @PostMapping("/getArticleByTitle")
    public Object getArticleListByName(@ApiParam(value = "文章标题",required = true) @RequestParam String title) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("articleList",articleService.getArticleByName(title));
        return map;
    }
    @ApiOperation(value = "通过文章id获取文章表")
    @PostMapping("/getArticleById")
    public Object getArticleListById(@ApiParam(value = "文章id",required = true) @RequestParam Integer id) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("article",articleService.getArticleById(id));
        return map;
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "新增文章信息")
    @PostMapping("/addArticle")
    public Object addArticle(@ApiParam(value = "新增文章信息",required = true) @RequestBody Article article) {
        return articleService.addArticle(article);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "修改文章信息")
    @PostMapping("/modifyArticle")
    public Object modifyArticle(@ApiParam(value = "修改文章信息",required = true) @RequestBody Article article) {
        return articleService.modifyArticle(article);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "删除文章信息")
    @PostMapping("/deleteArticle")
    public Object deleteArticle(@ApiParam(value = "文章id",required = true) @RequestParam Integer id) {
        return articleService.deleteArticle(id);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "文章上架")
    @PostMapping("/putOnArticle")
    public Object putOnArticle(@ApiParam(value = "文章id",required = true) @RequestParam Integer id) {
        return articleService.putOnArticle(id);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.ADMIN)
    @ApiOperation(value = "文章下架")
    @PostMapping("/takeDownArticle")
    public Object takeDownArticle(@ApiParam(value = "文章id",required = true) @RequestParam Integer id) {
        return articleService.takeDownArticle(id);
    }

    /**
     *
     * end-zwb
     */


    /**
     * start-gxd
     */
    /**
     * end-gxd
     */


    /**
     * start-lzh
     */
    /**
     * end-lzh
     */

    /**
     * start-hwf
     */
    /**
     * end-hwf
     */
}
